package com.cleaningcloud.erp.controller;

import com.cleaningcloud.common.core.domain.R;
import com.cleaningcloud.common.core.utils.UniqueIdUtils;
import com.cleaningcloud.common.core.web.controller.BaseController;
import com.cleaningcloud.common.core.web.domain.AjaxResult;
import com.cleaningcloud.erp.api.domain.ErpWareCommodityNumber;
import com.cleaningcloud.erp.mapper.ErpWareCommodityNumberMapper;
import com.cleaningcloud.erp.service.IPublicCommonService;
import com.cleaningcloud.erp.service.impl.PublicCommonServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 通用公共方法Controller
 *
 * @author cleaningcloud
 * @date 2024-10-17
 */
@RestController
@RequestMapping("/common")
public class PublicCommonController extends BaseController {


    @Autowired
    private IPublicCommonService publicCommonService;



    /**
     * 获取编号
     */
    @GetMapping("/getNo")
    public AjaxResult getNo()
    {
        return success(UniqueIdUtils.generateUniqueId());
    }



    @PostMapping("/selectByCommodityIdAndWareId")
    public ErpWareCommodityNumber selectByCommodityIdAndWareId(@RequestBody ErpWareCommodityNumber erpWareCommodityNumber){
        return publicCommonService.selectByCommodityIdAndWareId(erpWareCommodityNumber);
    }

    @PostMapping("/updateErpWareCommodityNumber")
    public R<Boolean> updateErpWareCommodityNumber(@RequestBody ErpWareCommodityNumber erpWareCommodityNumber){
        int i = publicCommonService.updateErpWareCommodityNumber(erpWareCommodityNumber);
        if(i > 0){
            return R.ok(true);
        }
        return R.fail("修改商品库存失败！");
    }

    @PostMapping("/insertErpWareCommodityNumber")
    public R<Boolean> insertErpWareCommodityNumber(@RequestBody ErpWareCommodityNumber erpWareCommodityNumber){
        int i = publicCommonService.insertErpWareCommodityNumber(erpWareCommodityNumber);
        if(i > 0){
            return R.ok(true);
        }
        return R.fail("新增商品库存失败！");
    }


}
